package com.handpay.zztong.hp;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.handpay.framework.utils.CommonUtils;
import com.handpay.framework.utils.DateUtils;
import com.handpay.zztong.hp.base.activity.ZZTongActivity;
import com.handpay.zztong.hp.bean.ActionBar;
import com.handpay.zztong.hp.bean.PurchaseStatus;
import com.handpay.zztong.hp.bean.PurchaseStatus.PurchaseEvent;
import com.handpay.zztong.hp.log.HPLog;

public class RedemptionResult extends ZZTongActivity {
	public TextView redemptionAmount,redemptionStatustv,redemptionTime,failReason,redemptionTimetv;
	private ImageView redemptionTimeline,failReasonLine;
	private LinearLayout redemptionTimell,failReasonll;
	private PurchaseStatus redeemList  = null ;
	private PurchaseEvent event_b= null,event_a= null;
	private TextView aptime_a,aptime_b,apstatus_a,apstatus_b;
	private ImageView precess_a,precess_b,connect_a;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.redemption_result);
		super.onCreate(savedInstanceState);
		if(getIntent() != null){
			if(getIntent() != null){
				redeemList = (PurchaseStatus)getIntent().getSerializableExtra("purchaseStatus");
				
			}
		}
		initView();
	}
	/**
	 * 初始化控件
	 */
	public void initView(){
		//初始化控件
//		findViewById(R.id.left_bar).setOnClickListener(this);
//		((TextView)findViewById(R.id.title)).setText(this.getString(R.string.redeemResult));
		redemptionAmount = (TextView)findViewById(R.id.redemptionAmount);
		redemptionStatustv = (TextView)findViewById(R.id.redemptionStuts);
		redemptionTimeline = (ImageView)findViewById(R.id.redemptionTimeline);
		redemptionTimell = (LinearLayout)findViewById(R.id.redemptionTimell);
		redemptionTimetv = (TextView)findViewById(R.id.redemptionTime);
		failReasonLine = (ImageView)findViewById(R.id.fail_reason_line);
		failReasonll = (LinearLayout)findViewById(R.id.fail_reason);
		failReason = (TextView)findViewById(R.id.failureReason);
		aptime_a = (TextView)findViewById(R.id.aptime_a);
		aptime_b = (TextView)findViewById(R.id.aptime_b);
		apstatus_a = (TextView)findViewById(R.id.apstatus_a);
		apstatus_b = (TextView)findViewById(R.id.apstatus_b);
		precess_a = (ImageView)findViewById(R.id.precess_a);
		precess_b = (ImageView)findViewById(R.id.precess_b);
		connect_a = (ImageView)findViewById(R.id.connectb);

		redemptionAmount.setText(CommonUtils.formatMoneyDouble(Double.parseDouble(redeemList.getAmount()+"")/100)+"元");
		if("00".equals(redeemList.getStatus())){
			redemptionTimeline.setVisibility(View.GONE);
			redemptionTimell.setVisibility(View.GONE);
			failReasonLine.setVisibility(View.GONE);
			failReasonll.setVisibility(View.GONE);
			redemptionStatustv.setText(redeemList.getStatusDesc()); 
			event_a = redeemList.getPurchaseList().get(0);
			event_b = redeemList.getPurchaseList().get(1);
			HPLog.e("yangjj------------------>>>>>>>>>>>>>>>>>", "event_a.getEventTime():" + event_a.getEventTime());			
			aptime_a.setText(DateUtils.formatDateToString(DateUtils.formatStringToDate(event_a.getEventTime(), "yyyyMMddHHmmss"), "yyyy-MM-dd HH:mm:ss"));
			apstatus_a.setText(event_a.getEventDesc());
			aptime_b.setText(DateUtils.formatDateToString(DateUtils.formatStringToDate(event_b.getEventTime(), "yyyyMMdd"), "yyyy-MM-dd"));
			apstatus_b.setText(event_b.getEventDesc());

			if("1".equals(event_a.getIsFinish()) && "0".equals(event_b.getIsFinish())){ 
				precess_a.setImageDrawable(getResources().getDrawable(R.drawable.processahover));
				connect_a.setImageDrawable(getResources().getDrawable(R.drawable.connectb));
				precess_b.setImageDrawable(getResources().getDrawable(R.drawable.processa));
			}			
			if("1".equals(event_a.getIsFinish()) && "1".equals(event_b.getIsFinish())){ 
				precess_a.setImageDrawable(getResources().getDrawable(R.drawable.processahover));
				connect_a.setImageDrawable(getResources().getDrawable(R.drawable.connectc));
				precess_b.setImageDrawable(getResources().getDrawable(R.drawable.processahover));
			}
			
		} else if("02".equals(redeemList.getStatus())){
			findViewById(R.id.redemption_success_status).setVisibility(View.GONE);
			redemptionTimetv.setText(DateUtils.formatDateToString(DateUtils.formatStringToDate(redeemList.getPurchaseTime(), "yyyyMMddHHmmss"), "yyyy-MM-dd HH:mm:ss"));
			failReason.setText(redeemList.getMessage());
			redemptionStatustv.setText(redeemList.getStatusDesc()); 
			redemptionStatustv.setTextColor(Color.RED);
		} else if("01".equals(redeemList.getStatus())){
			findViewById(R.id.redemption_success_status).setVisibility(View.GONE);
			failReasonll.setVisibility(View.GONE);
			redemptionTimetv.setText(DateUtils.formatDateToString(DateUtils.formatStringToDate(redeemList.getPurchaseTime(), "yyyyMMddHHmmss"), "yyyy-MM-dd HH:mm:ss"));
			redemptionStatustv.setText(redeemList.getStatusDesc());
		}
	}

	@Override
	protected boolean isShownTopBar() {
		return true;
	}

	@Override
	protected boolean isShownTabs() {
		return false;
	}
//	@Override
//	public void onLeftBar(View v) {
//		setResult(REQUEST_REDEEM_CODE);
//		super.onLeftBar(v);
//	}
	@Override
	public ActionBar getActivityActionBar() {
		setResult(REQUEST_REDEEM_CODE);
		return new ActionBar(this.getString(R.string.redeemResult), true);
	}
	
}
